//////////////////////////////////////////////////////////////////////////
//
// This file is a part of UKROP project.
// Copyright (c) Vladimir Gumenuk, 2008-2014.
//
// PROJECT:         Xort compiler
// FILE:            AlertObject.cpp - native object support (example)
// AUTHOR:          Vladimir Gumenuk
// DATE:            4-Sep-2014
//
//////////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "AlertObject.h"


CAlertObject::CAlertObject()
{
    m_dwRefCount = 0;
}

CAlertObject::~CAlertObject()
{
}

int CAlertObject::Invoke( lpcstr lpszName, XNIVariantArray *pArgs, XNIVariant& vResultOut )
{
    if( !lpszName )
        return FALSE;
    
    vResultOut.bType = xni_v;

    // void ShowAlert( string csTitle, string csText );

    if( strcmp( lpszName, "ShowAlert" ) == 0 )
    {
        if( !pArgs || pArgs->GetCount() != 2 )
            return FALSE;

        XNIVariant vTitle, vMessage;

        int iRet = pArgs->GetValue( 0, vTitle );
        if( iRet != XOK )
            return iRet;

        if( vTitle.bType != xni_str || !vTitle._str )
            return FALSE;

        iRet = pArgs->GetValue( 1, vMessage );
        if( iRet != XOK )
            return iRet;

        if( vMessage.bType != xni_str || !vMessage._str )
            return FALSE;

        MessageBoxA( NULL, vMessage._str, vTitle._str, MB_OK );
    }
    else
        return FALSE;

    return XOK;
}